package com.ruoyi.passenger.controller;

import com.alibaba.fastjson2.JSON;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.passenger.domain.Orderinfo;
import com.ruoyi.passenger.service.IOrderinfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 【请填写功能名称】Controller
 * 
 * @author ruoyi
 * @date 2024-07-03
 */
@RestController
@RequestMapping("/orderinfo")
public class OrderinfoController extends BaseController
{

    @Autowired
    RedisTemplate redisTemplate;



    @Autowired
    private IOrderinfoService orderinfoService;

    /**
     * 查询【请填写功能名称】列表
     */
    @RequiresPermissions("driver:orderinfo:list")
    @GetMapping("/list")
    public TableDataInfo list(Orderinfo orderinfo)
    {
        startPage();
        List<Orderinfo> list = orderinfoService.selectOrderinfoList(orderinfo);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @RequiresPermissions("driver:orderinfo:export")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Orderinfo orderinfo)
    {
        List<Orderinfo> list = orderinfoService.selectOrderinfoList(orderinfo);
        ExcelUtil<Orderinfo> util = new ExcelUtil<Orderinfo>(Orderinfo.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @RequiresPermissions("driver:orderinfo:query")
    @GetMapping(value = "/{orderId}")
    public AjaxResult getInfo(@PathVariable("orderId") Long orderId)
    {
        return success(orderinfoService.selectOrderinfoByOrderId(orderId));
    }

    /**
     * 新增【请填写功能名称】
     */
    @RequiresPermissions("driver:orderinfo:add")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Orderinfo orderinfo)
    {
        return toAjax(orderinfoService.insertOrderinfo(orderinfo));
    }

    /**
     * 修改【请填写功能名称】
     */
    @RequiresPermissions("driver:orderinfo:edit")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Orderinfo orderinfo)
    {
        return toAjax(orderinfoService.updateOrderinfo(orderinfo));
    }

    @Autowired
    KafkaTemplate kafkaTemplate;

    /**
     * 删除【请填写功能名称】
     */
    @RequiresPermissions("driver:orderinfo:remove")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orderIds}")
    public AjaxResult remove(@PathVariable Long[] orderIds)
    {
        return toAjax(orderinfoService.deleteOrderinfoByOrderIds(orderIds));
    }
    @PostMapping("saveorder")
    public AjaxResult saveOrder(@RequestBody Orderinfo orderinfo)
    {
        Long userId = SecurityUtils.getUserId();
        String userName = SecurityUtils.getUsername();

        orderinfo.setUserName(userName);

        redisTemplate.opsForHash().put("Orderinfo","userId:"+userId, orderinfo);

        kafkaTemplate.send("my-2109A-topic",JSON.toJSONString(orderinfo));
        return AjaxResult.success();
    }



}
